const utils = {
  toast: (title = "哎呀，出错了") => {
    wx.showToast({
      title: title,
      icon: "none",
      mask: true,
      duration: 1000,
    });
  },

  getPastTime(oldTime) {
    const current = new Date().getTime();
    const old = new Date(oldTime).getTime();
    const pastMinutes = parseInt((current - old) / 1000 / 60);
    const pastHours = parseInt(pastMinutes / 60);
    const pastDays = parseInt(pastHours / 24);
    const pastMonths = parseInt(pastDays / 30);
    const pastYears = parseInt(pastMonths / 12);
    const pastTime =
      pastYears || pastMonths || pastDays || pastHours || pastMinutes || "几";
    let text = "";
    switch (pastTime) {
      case pastYears:
        text = "年前";
        break;
      case pastMonths:
        text = "月前";
        break;
      case pastDays:
        text = "日前";
        break;
      case pastHours:
        text = "小时前";
        break;
      case pastMinutes:
        text = "分钟前";
        break;
      case "几":
        text = "秒前";
        break;
    }
    return pastTime + text;
  },

};

wx.utils = utils;

export default utils;
